home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cc02.zip / ENTER.C < prev    next >
Text File  |  1985-11-25  |  9KB  |  412 lines

  1. /****************************************************************
  2. * ENTER.C                            *
  3.  
  4. Release 7: RBBS 4.1 Edit 02 - Better prompt in entermsg
  5. Release 6: RBBS 4.1 Edit 01 - Fixed edit problem in edit_txt
  6.                 - Added L command option to edit_txt
  7.                 - Allow "personal" messages everywhere
  8.                 - Cannot send to self anymore
  9. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  10.                 - Inserted PERSONLY in check_to
  11.                 - Fixed potential problem in save_draft
  12. Release 1: RBBS 4.0 Edit 18
  13.  
  14. * This file contains the functions:
  15.  
  16. * entermsg    calls check_to, get_subj, get_text, and edit_draft
  17.  
  18. * check_to    prompts for To:, calls checkuser
  19.  
  20. * get_subj    prompts for Subject string
  21.  
  22. * get_text    prompts for up to 24 text lines
  23.  
  24. * edit_draft    command dispatch
  25.  
  26. * save_draft    appends the message to current .MSG file
  27.  
  28. * edit_sum    offers to change the To: and Subject: lines
  29.  
  30. * edit_txt    prompts for line number to change and offers the
  31.                 line for editting
  32.  
  33. ****************************************************************/
  34. #include    <bdscio.h>
  35. #include    "rbbs4.h"
  36.  
  37. /***************************************************************/
  38. entermsg(fd,ufd,u,s,tosys)    /* ROUTINE TO CONTROL MSG ENTRY*/
  39. int    fd,ufd;
  40. struct    _user    *u;
  41. struct    _sum    *s;
  42. int    tosys;
  43. {
  44.     s->msgno = ++lastmsg;;
  45.     s->mstat = TRUE;
  46. #if    DATETIME
  47.     get_date();
  48. #endif
  49.     strcpy(s->date,sysdate);
  50.     if (tosys)
  51.         strcpy(s->tnm,"SYSOP");
  52.     else
  53.         if (!check_to(ufd,s,u,TRUE))
  54.             return;
  55.     strcpy(s->fnm,u->nm);
  56.     if (tosys)
  57.         strcpy(s->subj,"MSG FOR SYSOP");
  58.     else
  59.     {
  60.         *(s->subj) = 0;
  61.         get_subj(s);
  62.     }
  63.     s->lct = get_text(s,1);
  64.     edit_draft(fd,ufd,u,s);
  65. }
  66. /***************************************************************/
  67. check_to(fd,s,u,flag)    /* GETS THE NAME OF THE MSG RECIPIENT    */
  68. int    fd,flag;
  69. struct    _user    *u;
  70. struct    _sum    *s;    /* CHECKS FOR VALID USER - PERMITS     */
  71. {            /* OVERRIDE - PERMITS ALL        */
  72.  
  73.     struct    _user    x;
  74.     char    name[NAMELGTH+1];
  75.  
  76. #if    !PERSONLY
  77.     if (!expert && flag && personal)
  78.     {
  79. outstr("The current message file, 'PERSONAL' is for private mail only.",2);
  80. outstr("If you wish to send to a specific individual and you don't care",2);
  81. outstr("who can read it (or send to 'ALL'), use the F Command to select",1);
  82. outstr("the 'GENERAL' or some other message file at the COMMAND prompt.",1);
  83.         crlf(1);
  84.         outstr("To abort, hit RETURN.",1);
  85.         outstr("Enter To:",3);
  86.     }
  87. #endif
  88.     do
  89.     {
  90.         crlf(1);
  91.         if ( getname(name,"To:        "))
  92.         {
  93.             if (personal)
  94.             {
  95.                 crlf(1);
  96.                 return FALSE;
  97.             }
  98.             else
  99.             {
  100.                 outstr("ALL",0);
  101.                 strcpy(s->tnm,"ALL");
  102.                 return(TRUE);
  103.             }
  104.  
  105.         }
  106.         if ( !strcmp(name,u->nm))
  107.         {
  108.             outstr("Can't send to yourself!",3);
  109.             crlf(1);
  110.             *sav = 0;
  111.             break;
  112.         }
  113.         if ( !checkuser(fd,name,x,0) )
  114.         {
  115.             crlf(1);
  116.             sprintf(tmpstr," %s",name);
  117.             strcat(tmpstr," is NOT a user of this system.");
  118. #if    SENDOK
  119.             strcat(tmpstr,"  Use anyway");
  120.             if ( getyn(tmpstr))
  121.             {
  122.                 strcpy(s->tnm,name);
  123.                 return TRUE;
  124.             }
  125. #else
  126.             strcat(tmpstr,"  Please try again.");
  127.             outstr(tmpstr,2);
  128. #endif
  129.         }
  130.         else
  131.         {
  132.             strcpy(s->tnm,name);
  133.             return TRUE;
  134.         }
  135.     } while (TRUE);
  136. }
  137. /***************************************************************/
  138. get_subj(s)        /* GETS SUBJECT - VARIABLE LENGTH    */
  139. struct    _sum    *s;
  140. {
  141.     do
  142.     {
  143.         outstr("Subject:   ",4);
  144.         instr(s->subj,s->subj,SUMSIZE-1);
  145.     }    while (!strlen(s->subj));
  146.     crlf(1);
  147. }
  148. /***************************************************************/
  149. get_text(s,i)        /* GETS TEXT FOR MESSAGE - UP TO 24     */
  150. struct    _sum    *s;    /* LINES                */
  151. int    i;
  152. {
  153.     int    j;
  154.  
  155.     setptr(m,lp);
  156.     strcpy(tmpstr,"Enter Text");
  157.     if (!expert)
  158.         strcat(tmpstr," (?<cr> on a new line for help)");
  159.     strcat(tmpstr,":");
  160.     outstr(tmpstr,2);
  161. #if    RULER
  162.     if (!expert)
  163.         outstr("     ---------------------------------------------------------------",1);
  164. #endif
  165.     setmem(sav,SECSIZ,0);
  166.     for( j = i; j <= MLINELIM; j++)
  167.     {
  168.         sprintf(tmpstr,"%2d>: ",j);
  169.         outstr(tmpstr,4);
  170.         cflg = 1;
  171.         instr("",lp[j],MLINESIZ-1);
  172. #if    PCREND
  173.         if ( (strlen(lp[j]) == 1) && (*lp[j] == '.') )
  174. #else
  175.         if ( !*(lp[j]) )
  176. #endif
  177.         {
  178.             crlf(1);
  179.             return --j;
  180.         }
  181.         if ( (strlen(lp[j]) == 1) && (*lp[j] == '?') )
  182.         {
  183.             crlf(1);
  184.             bufinmsg("MSGHELP");
  185.             outstr("Hit RETURN to resume input: ",0);
  186.             cflg = 3;
  187.             instr("",tmpstr,1);
  188.             s->lct = --j;
  189.             prnt_txt(s,TRUE);
  190.         }
  191.         if (j >= MLINELIM-3)
  192.         {
  193.             if (belflg)
  194.                 bputs("\07");
  195.             *tmpstr = 0;
  196.             if (j == MLINELIM)
  197.                 strcpy(tmpstr,"No ");
  198.             else
  199.                 sprintf(tmpstr,"%d ",MLINELIM-j);
  200.             strcat(tmpstr,"line");
  201.             if (MLINELIM - j - 1)
  202.                 strcat(tmpstr,"s");
  203.             strcat(tmpstr," left!");
  204.             outstr(tmpstr,3);
  205.         }
  206.     }
  207.     crlf(1);
  208.     return(MLINELIM);
  209. }
  210. /***************************************************************/
  211. edit_draft(fd,ufd,u,s)    /* EDIT DRAFT MESSAGE    */
  212. int    fd,ufd;
  213. struct    _user    *u;
  214. struct    _sum    *s;
  215. {
  216.     int    cmd;
  217.     char    cmd2[2];
  218.  
  219.     cmd = FALSE;
  220.     while (TRUE)
  221.     {
  222.         switch(cmd)
  223.         {
  224.             case 'H':
  225.                 edit_sum(ufd,s,u);
  226.                 break;
  227.  
  228.             case 'L':
  229.                 crlf(1);
  230.                 prnt_sum(s);
  231.                 prnt_txt(s,TRUE);
  232.                 break;
  233.  
  234.             case 'S':
  235.                 if (save_draft(fd,s))
  236.                     return;
  237.                 break;
  238.  
  239.             case 'R':
  240.                 if (!personal)
  241.                     break;
  242.                 if (!save_draft(fd,s))
  243.                     break;
  244.                 if (!expert)
  245. outstr("Use 'A' to Abort, or 'H' to edit 'To:', then 'S' or 'R' to Store again.",2);
  246.                 s->msgno = ++lastmsg;
  247.                 break;
  248.  
  249.             case 'C':
  250.                 s->lct = get_text(s,s->lct+1);
  251.                 break;
  252.  
  253.             case 'E':
  254.                 edit_txt(s);
  255.                 break;
  256.  
  257.             case 'A':
  258.                 if (getyn("Abort EnterMsg"))
  259.                     return;
  260.                 else
  261.                     break;
  262.  
  263.             case 'X':
  264.                 expert = !expert;
  265.                 break;
  266.  
  267.             case '?':
  268.                 crlf(1);
  269.                 bufinmsg("SELHELP");
  270.                 break;
  271.  
  272.             default:
  273.                 break;
  274.         }
  275.     strcpy(tmpstr,"SELECT: ");
  276.     if (!expert)
  277.         strcat(tmpstr,"H, L, E, C, A, R, S, X, or ?: ");
  278.     outstr(tmpstr,4);
  279.     instr("",cmd2,1);
  280.     crlf(1);
  281.     cmd = *cmd2 = toupper(*cmd2);
  282.     }
  283. }
  284. /***************************************************************/
  285. save_draft(fd,s)    /* WRITES NEW MSG TO MESSAGE.CCC &     */
  286. int    fd;
  287. struct    _sum    *s;
  288. {        
  289.     struct    _sum    s2;
  290.  
  291.     if (!s->lct)
  292.     {
  293.         outstr("Cannot Store an empty message!",1);
  294.         outstr("Use either A)bort to quit, or",1);
  295.         outstr("C)continue to add text.",1);
  296.         return FALSE;
  297.     }
  298. #if    LOCKEM
  299.     if (lokrec(fd,-1))
  300.         ioerr("locking .MSG file");
  301. #endif
  302.     msgct = loadsum(fd,s2); /* Loads last msg no if updated    */
  303.     msg_info(msgct,FALSE);
  304.     s->msgno = ++lastmsg;
  305.     ++msgct;
  306.     mndx[msgct+1] = ritemsg(fd,mndx[msgct],s,lp[1]);
  307.     mno[msgct] = s->msgno;
  308.     mno[msgct+1] = 0;
  309. #if    LOCKEM
  310.     frerec(fd,-1);
  311. #endif
  312.     close(fd);
  313.     fd = open(msgfile,2);
  314.     sprintf(tmpstr,"Message stored as #%d.",s->msgno);
  315.     outstr(tmpstr,1);
  316.     return TRUE;
  317. }
  318. /***************************************************************/
  319. edit_sum(ufd,s,u)        /* EDITS THE HEADER PORTION OF THE MSG */
  320. int    ufd;
  321. struct    _user    *u;
  322. struct _sum    *s;
  323. {
  324.     crlf(1);
  325.     sprintf(tmpstr,"To: %s OK",s->tnm);
  326.     if (!getyn(tmpstr))
  327.     {
  328.         check_to(ufd,s,u,FALSE);
  329.         crlf(1);
  330.     }
  331.     sprintf(tmpstr,"Re: %s OK",s->subj);
  332.     if (!getyn(tmpstr))
  333.         get_subj(s);
  334. }
  335. /***************************************************************/
  336. edit_txt(s)        /* EDITS THE TEXT PORTION OF MSG    */
  337. struct    _sum    *s;
  338. {
  339.     int    i;
  340.     int    j;
  341.     char    input[4];
  342.  
  343.     do
  344.     {
  345.         if (!expert)
  346.             strcpy(tmpstr,"Enter l");
  347.         else
  348.             strcpy(tmpstr,"L");
  349.         strcat(tmpstr,"ine number");
  350.         if (!expert)
  351.             strcat(tmpstr," to edit, or 0 to exit");
  352.         strcat(tmpstr,": ");
  353.         outstr(tmpstr,4);
  354.         instr("",input,3);
  355.         if ( toupper(*input) == 'L')
  356.         {
  357.             crlf(1);
  358.             prnt_txt(s,TRUE);
  359.         }
  360.         else
  361.         {
  362.             i = atoi(input);
  363.             setmem(sav,SECSIZ,0);
  364.             if (!i)
  365.             {
  366.                 crlf(1);
  367.                 break;
  368.             }
  369.             if ( abs(i) > 0 && abs(i) <= s->lct)
  370.             {
  371.                 if ( i < 0)
  372.                 {
  373.                     i = abs(i);
  374.                     if ( (s->lct)++ < MLINELIM)
  375.                         strcpy(lp[s->lct],lp[(s->lct)-1]);
  376.                     for (j = (s->lct)-1; j > i; j--)
  377.                         strcpy(lp[j],lp[j-1]);
  378.                     if ( (s->lct) > MLINELIM )
  379.                         s->lct = MLINELIM;
  380.                     *lp[i] = 0;
  381.                 }
  382.                 sprintf(tmpstr,"%2d>: ",i);
  383.                 outstr(tmpstr,4);
  384.                 cflg = 1;
  385.                 instr(lp[i],lp[i],ML